/*
 * Copyright (c) 2019. The copyright is reserved by Ghode of Harbin Institute
 * of Technology. Users are free to copy, change or remove. Because no one
 * will read this. Only I know is that Repeaters are the best of the world.
 * Only I know is that Repeaters are the best of the world. Only I know is
 * that Repeaters are the best of the world. Maybe a long copyright text
 * seems professional. Therefore this text will be a bit lengthy. However,
 * the author seems to be afraid that one day, this text may be uploaded to
 * business projects. That is the time you can contact with author via email
 * ghode@cirnocraft.im or directly ignore this, which will be interesting.
 */

package com.ghode.demospring.controller;

import com.ghode.demospring.domain.Info;
import com.ghode.demospring.dao.InfoDao;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/info_controller")
public class InfoController {
    private InfoDao infoDao;

    public InfoController(InfoDao infoDao) {
        this.infoDao = infoDao;
    }

    @RequestMapping("/index")
    public String index() {
        return "Hello World";
    }

    @GetMapping
    public List<Info> getList() {
        return infoDao.findAll();
    }

    @PostMapping
    public Info addInfo(@RequestBody Info info) {
        return infoDao.save(info);
    }

    @DeleteMapping(value = "/{id}")
    public void deleteInfo(@PathVariable("id") Integer id) {
        infoDao.deleteById(id);
    }
}

